package com.jishuo.nontax.api.socket.handle;

import com.jishuo.base.bean.BaseResult;
import com.jishuo.base.bean.ErrorCodeEnum;
import com.jishuo.base.util.SpringContextUtil;
import com.jishuo.nontax.api.socket.ApiHandle;
import com.jishuo.nontax.bfc.service.OnlineOrderService;
import com.jishuo.nontax.bfc.service.StudentService;
import org.dom4j.Element;

/**
 * 学生缴费接口处理
 * @auther dinggaofei
 * @Date 2023/2/10 17:07
 */
public class StudentApi implements ApiHandle {
    @Override
    public BaseResult execute(String head, Element body) {
        if ("getStudent".equals(head)) { // 获取学生票据
            String studnetnum = body.elementText("studentnum");
            if (studnetnum == null) {
                return new BaseResult(ErrorCodeEnum.PARAM_ERR.getCode(), "参数错误[studentnum]");
            }
            StudentService studentService = (StudentService) SpringContextUtil.getBean("studentService");
            return studentService.getStudent(studnetnum);
        }else if ("getStudentOnLine".equals(head)) { // 获取学生票据
            String studnetnum = body.elementText("billnum");
            if (studnetnum == null) {
                return new BaseResult(ErrorCodeEnum.PARAM_ERR.getCode(), "参数错误[billnum]");
            }
            StudentService studentService = (StudentService) SpringContextUtil.getBean("studentService");
            BaseResult result = studentService.getStudent(studnetnum);
            //返回数据对象
            if (result.isSuccess()) {
                result.setData(("<retCode>0000</retCode><retMsg>success</retMsg>"+result.getData()));
            }else{
                result.setData(("<retCode>9999</retCode><retMsg>fail</retMsg>"+result.getData()));
            }
            return result;
        }  else if ("setStudentPayInfo".equals(head)) {  // 学生缴费
            String studentnum = body.elementText("studentnum");
            String paybankdt = body.elementText("paybankdt");
            String bankaffirm = body.elementText("bankaffirm");
            String bankstation = body.elementText("bankstation");
            String paychnl = body.elementText("paychnl");
            String payeraccount = body.elementText("payeraccount");
            StudentService studentService = (StudentService) SpringContextUtil.getBean("studentService");
            BaseResult result = studentService.setStudentPayInfo(studentnum, paybankdt, bankaffirm, bankstation,paychnl,payeraccount);
            int n = result.isSuccess() ? 1 : 0;
            result.setData("<returninfo>" + n + "</returninfo>");
            return result;

        } else if ("setStudentDepositOnLine".equals(head)) {  // 学生缴费
            String studentnum = body.elementText("billnum");
            String paybankdt = body.elementText("paybankdt");
            String bankaffirm = body.elementText("bankaffirm");
            String bankstation = "online";
            String paychnl = body.elementText("paychnl");
            String payeraccount = body.elementText("payeraccount");
            StudentService studentService = (StudentService) SpringContextUtil.getBean("studentService");
            BaseResult result = studentService.setStudentPayInfo(studentnum, paybankdt, bankaffirm, bankstation,paychnl,payeraccount);
            //返回数据对象
            if (result.isSuccess()) {
                result.setData("<retCode>0000</retCode><retMsg>success</retMsg>");
            }else{
                result.setData("<retCode>9999</retCode><retMsg>fail</retMsg>");
            }
            return result;
        }else if ("findPayInfoOnLine".equals(head)) {
            String billtype = body.elementText("billtype");
            String billnum = body.elementText("billnum");
            OnlineOrderService onlineOrderService = (OnlineOrderService) SpringContextUtil.getBean("onlineOrderService");
            BaseResult result = onlineOrderService.findPayInfoOnLine(billnum, Integer.valueOf(billtype));
            //返回数据对象
            if (result.isSuccess()) {
                result.setData("<retCode>0000</retCode><retMsg>success</retMsg>"+result.getData());
            }else{
                result.setData("<retCode>9999</retCode><retMsg>fail</retMsg>");
            }
            return result;
        }else if ("listPayInfoOnLine".equals(head)) {
            String paydate = body.elementText("paydate");
            OnlineOrderService onlineOrderService = (OnlineOrderService) SpringContextUtil.getBean("onlineOrderService");
            BaseResult result = onlineOrderService.listPayInfoOnLine(paydate);
            //返回数据对象
            if (result.isSuccess()) {
                result.setData("<retCode>0000</retCode><retMsg>success</retMsg>"+result.getData());
            }else{
                result.setData("<retCode>9999</retCode><retMsg>fail</retMsg>");
            }
            return result;
        }

        return null;
    }
}
